package com.sgb.kjwl.viewmodel.pick;

import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.text.TextUtils;

import androidx.databinding.ObservableField;
import androidx.lifecycle.MutableLiveData;

import com.sgb.capital.callback.AbstractOnClickPopListener;
import com.sgb.capital.callback.Constants;
import com.sgb.capital.utils.Utils;
import com.sgb.capital.view.pop.TipPop;
import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.api.NewAPIManager;
import com.sgb.kjwl.api.service.UploadAPI;
import com.sgb.kjwl.model.EnquiryImAlternateEntity;
import com.sgb.kjwl.model.entity.CallPhoneEntity;
import com.sgb.kjwl.view.event.WebEvent;
import com.sgb.kjwl.view.ui.activity.material.ConcreteDetailActivity2;
import com.sgb.kjwl.view.widget.CallPhonePopWindow;
import com.sgb.link.utils.Preferences;
import com.sgb.member.entity.QualityMemberBean2;
import com.sgb.member.weight.UploadFileBean;
import com.swgk.core.base.api.ICallBack;
import com.sgb.kjwl.model.entity.lease.CompanyInfoEntity;
import com.sgb.kjwl.model.entity.transport.MapChatEntity;
import com.sgb.kjwl.repository.PickRepertory;
import com.swgk.core.event.EventConstant;
import com.sgb.link.event.LeaseEvent;
import com.sgb.kjwl.view.ui.activity.WebViewX5Fragment;
import com.sgb.kjwl.view.ui.activity.pick.PickInquireByLetterActivity;
import com.sgb.member.entity.QualityMemberBean;
import com.sgb.member.ui.activity.MemberInviteJoinActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.im.immodel.IMUtils;
import com.swgk.core.util.MToast;
import com.swgk.core.util.SharedPreferenceUtil;

import org.greenrobot.eventbus.EventBus;

import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;
import razerdp.basepopup.BasePopupSDK;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class H5Model extends BaseViewModel {
    public ObservableField<String> areaCode = new ObservableField<>("");
    private WebViewX5Fragment fragment3;
    private PickRepertory repertory;
    private int page = 1;
    private int size = 10;
    public int total;

    public H5Model(WebViewX5Fragment fragment3, PickRepertory repertory) {
        this.fragment3 = fragment3;
        this.repertory = repertory;
        areaCode.set(repertory.getAreaCode());
    }

    public String getAreaNameModel() {
        return repertory.getAreaName();
    }

    public String getAreaCodeModel() {
        return repertory.getAreaCode();
    }

    public void checkToken(String tag) {
        DialogHelper.showProgressDialog(fragment3.getActivity(), null, "获取信息中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getShoppingCarAPI().checkToken().enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    if ("shopping_car".equals(tag)) {
                        fragment3.checkTokenView();
                    } else {
                        fragment3.checkAllowBid("jingjia", 0,
                                -100);
                    }
                } else {
                    if (!"Miss_Permission".equals(response.body().getCode())) {
                        fragment3.toLogin();
                    } else {
                        MToast.showToast(fragment3.getActivity(), response.body().getMsg());
                    }
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }


    public String getToken() {
        return SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, "");
    }

    // 清除登录信息
    public void logOutUserInfo() {
        SharedPreferenceUtil.getInstance().saveString(SharedPreferenceUtil.resourcePCToken, "");
        SharedPreferenceUtil.getInstance().saveString(SharedPreferenceUtil.resourceAPPToken, "");
        SharedPreferenceUtil.getInstance().saveString(SharedPreferenceUtil.LOGIN_TOKEN, "");
        SharedPreferenceUtil.getInstance().saveString(SharedPreferenceUtil.LOGIN_PC_TOKEN, "");
        repertory.saveToken("");
        repertory.saveAccount("");

//        NimUIKit.setAccount("");
//        AVChatKit.setAccount("");
        Preferences.saveUserAccount("");
        Preferences.saveUserToken("");

    }


    public void checkAllowBidQuestion(String bidNo, String bidType) {
        DialogHelper.showProgressDialog(fragment3.getActivity(), null, "获取信息中...", 0, false, null).setCanceledOnTouchOutside(false);
        Map map = new HashMap();
        map.put("bidNo", bidNo);
        APIManager.getInstance().getPickAPI().checkAllowBidQuestion(map).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_FAIL)) {
                    MToast.showToast(fragment3.getActivity(), response.body().getMsg());
//                    fragment3.checkAllowDialog(response.body().getMsg());

                } else {
                    if (!TextUtils.isEmpty(bidType)) {
                        PickInquireByLetterActivity.start(fragment3.getActivity(), bidNo, "jj", Integer.parseInt(bidType));
                    }
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void checkAllowTenderQuestion(String tenderNo, String tenderingType) {
        DialogHelper.showProgressDialog(fragment3.getActivity(), null, "获取信息中...", 0, false, null).setCanceledOnTouchOutside(false);
        Map map = new HashMap();
        map.put("tenderNo", tenderNo);
        APIManager.getInstance().getPickAPI().checkAllowTenderQuestion(map).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) return;
                if (response.body().getState().equals(APIManager.RESPONSE_FAIL)) {
                    fragment3.checkAllowDialog(response.body().getMsg());
                } else {
                    PickInquireByLetterActivity.start(fragment3.getActivity(), tenderNo, "zb", tenderingType);
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });

    }

    /**
     * 检查当前用户是否允许集采函询
     *
     * @param bidNo
     */
    public void checkAllowJcQuestion(String bidNo, String inquiryUserMemberNo) {
        DialogHelper.showProgressDialog(fragment3.getActivity(), null, "获取信息中...", 0, false, null).setCanceledOnTouchOutside(false);
//        Map map = new HashMap();
//        map.put("no", bidNo);
        APIManager.getInstance().getPickAPI().checkAllowJcQuestion(bidNo).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_FAIL)) {
                    fragment3.checkAllowDialog(response.body().getMsg());

                } else {
                    PickInquireByLetterActivity.start(fragment3.getActivity(), bidNo, "jc", inquiryUserMemberNo);
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    /**
     * 验证当前用户是否允许函询--供方发起
     *
     * @param id
     */
    public void checkAllowFactoryJcQuestion(String id, String inquiryUserMemberNo) {
        DialogHelper.showProgressDialog(fragment3.getActivity(), null, "获取信息中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPickAPI().checkAllowFactoryJcQuestion(id).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_FAIL)) {
                    fragment3.checkAllowDialog(response.body().getMsg());
                } else {
                    PickInquireByLetterActivity.start(fragment3.getActivity(), id, "cjjc", inquiryUserMemberNo);
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void findCustomerServiceImAccount(String customerServiceContactsId) {
        DialogHelper.showProgressDialog(fragment3.getActivity(), null, "获取信息中...", 0, false, null).setCanceledOnTouchOutside(false);
        Map map = new HashMap();
        map.put("customerServiceContactsId", customerServiceContactsId);
        APIManager.getInstance().getPickAPI().getfindCustomerServiceImAccount(map).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_FAIL)) {
//                    MToast.showToast(fragment3.getActivity(), response.body().getMsg());
                    fragment3.checkAllowDialog(response.body().getMsg());
                } else {
                    String dataIMid = response.body().getData().toString();
                    IMUtils.getInstance().buildSingleTalking(dataIMid);
//                    NimUIKit.startP2PSession(fragment3.getActivity(), dataIMid);
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });

    }

    public void toIm(String tel) {
        APIManager.getInstance().getDriverAPI().getNewMapChatList(tel).enqueue(new Callback<BaseEntity<MapChatEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<MapChatEntity>> call, Response<BaseEntity<MapChatEntity>> response) {
                if (response.body() == null) {
                    return;
                }

                if (response.body().getState().equals("ok") && response.body().getData() != null && !TextUtils.isEmpty(response.body().getData().getImAccount())) {
                    String dataIMid = response.body().getData().getImAccount();
                    IMUtils.getInstance().buildSingleTalking(dataIMid);
//                    NimUIKit.startP2PSession(fragment3.getActivity(), id);
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<MapChatEntity>> call, Throwable t) {
            }
        });
    }

    public void delOrder(String orderNo) {
        DialogHelper.showProgressDialog(fragment3.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(true);
        APIManager.getInstance().getSelfOwnerAPI().orderDel(orderNo).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) {
                    return;
                }
                if (response.body().getState().equals("ok")) {
                    MToast.showToast(fragment3.getActivity(), "删除成功");
                    fragment3.getActivity().finish();
                } else {
                    MToast.showToast(fragment3.getActivity(), response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void cancel(String orderNo) {
        DialogHelper.showProgressDialog(fragment3.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(true);
        APIManager.getInstance().getSelfOwnerAPI().orderCancel(orderNo).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) {
                    return;
                }
                if (response.body().getState().equals("ok")) {

                    fragment3.getActivity().finish();
                } else {
                    MToast.showToast(fragment3.getActivity(), response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void confirm(String orderNo) {
        DialogHelper.showProgressDialog(fragment3.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(true);
        APIManager.getInstance().getSelfOwnerAPI().orderConfirm(orderNo).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) {
                    return;
                }
                if (response.body().getState().equals("ok")) {

                    fragment3.getActivity().finish();
                } else {
                    MToast.showToast(fragment3.getActivity(), response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });

    }

    //发车
    public void startCar(String orderNo) {
        DialogHelper.showProgressDialog(fragment3.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(true);
        APIManager.getInstance().getSelfOwnerAPI().carStart(orderNo).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) {
                    return;
                }
                if (response.body().getState().equals("ok")) {

                    fragment3.getActivity().finish();
                } else {
                    MToast.showToast(fragment3.getActivity(), response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    //到达
    public void endCar(String orderNo) {
        DialogHelper.showProgressDialog(fragment3.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(true);
        APIManager.getInstance().getSelfOwnerAPI().carEnd(orderNo).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) {
                    return;
                }
                if (response.body().getState().equals("ok")) {

                    fragment3.getActivity().finish();
                } else {
                    MToast.showToast(fragment3.getActivity(), response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void enquiryDelete(String no) {
        DialogHelper.showProgressDialog(fragment3.getActivity(), null, "删除中...", 0, false, null).setCanceledOnTouchOutside(false);
        NewAPIManager.getInstance().getProductInquiryAPI().enquiryDelete(no).enqueue(new Callback<BaseEntity<Object>>() {
            @Override
            public void onResponse(Call<BaseEntity<Object>> call, Response<BaseEntity<Object>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) {
                    showCancelPop("操作超时", 3);
                    return;
                }
                if (response.body().getState().equals("ok")) {
                    MToast.showToast(fragment3.getContext(), "删除成功");
                    EventBus.getDefault().post(LeaseEvent.make().setMessageTag(EventConstant.EVENT_BAOJIA_REFRESH));
                    fragment3.getActivity().finish();
                } else {
                    if ("1001".equals(response.body().getCode())) {
                        showCancelPop("该条数据已在其他端\n" +
                                "或被其他账号删除", 2);
                    }
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<Object>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void enquiryCancel(String no) {
        DialogHelper.showProgressDialog(fragment3.getActivity(), null, "取消中...", 0, false, null).setCanceledOnTouchOutside(false);
        NewAPIManager.getInstance().getProductInquiryAPI().enquiryCancel(no).enqueue(new Callback<BaseEntity<Object>>() {
            @Override
            public void onResponse(Call<BaseEntity<Object>> call, Response<BaseEntity<Object>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) {
                    return;
                }
                if (response.body().getState().equals("ok")) {
                    EventBus.getDefault().post(LeaseEvent.make().setMessageTag(EventConstant.EVENT_BAOJIA_REFRESH));
                    fragment3.setType("1");
                    fragment3.setStatus("4");
                    EventBus.getDefault().postSticky(WebEvent.make().setMessageTag(EventConstant.EVENT_WEBVIEW_RELOAD));
                } else {
                    if ("1001".equals(response.body().getCode())) {
                        showCancelPop("该条数据已删除", 1);
                    }
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<Object>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    //通过企业no获取企业信息
    public void getCompany(String companyNo, String type) {
        DialogHelper.showProgressDialog(fragment3.getActivity(), "获取信息中...").setCanceledOnTouchOutside(false);
        APIManager.getInstance().getLeaseMapAPI().getCompanyImgByNo(companyNo, type).enqueue(new ICallBack<BaseEntity<CompanyInfoEntity>>(true) {
            @Override
            public void onSuccess(BaseEntity<CompanyInfoEntity> data) {
                CompanyInfoEntity entity = data.getData();
                if (entity != null) {
                    QualityMemberBean memberBean = new QualityMemberBean();
                    memberBean.setCompanyId(entity.getId());
                    memberBean.setCompanyNo(companyNo);
                    memberBean.setCompanyName(entity.getName());
                    memberBean.setServiceType(entity.getServiceType());
                    memberBean.setServiceTypeName(entity.getServiceType());
                    memberBean.setAddress(entity.getAddress());
                    memberBean.setProvinceNo(entity.getProvinceNo());
                    memberBean.setCityNo(entity.getCityNo());
                    memberBean.setDistrictNo(entity.getDistrictNo());
                    MemberInviteJoinActivity.start(fragment3.getActivity(), memberBean);
                }
            }

        });

    }

    public void followForTeam(String no, String type, boolean isAttention) {
        DialogHelper.showProgressDialog(fragment3.getActivity(), null, "取消中...", 0, false, null).setCanceledOnTouchOutside(false);
        NewAPIManager.getInstance().getTeamNewInterfaceAPI().follow(isAttention, no, Integer.parseInt(type)).enqueue(new Callback<BaseEntity<String>>() {
            @Override
            public void onResponse(Call<BaseEntity<String>> call, Response<BaseEntity<String>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }

//                if (((String)response.body().getData()).contains("成功")){
//                    MToast.showToast(fragment3.getActivity(),(String) response.body().getData());
//                    fragment3.setFollowStatus(response.body().getState().equals(APIManager.RESPONSE_OK));
//                }else {
//                    MToast.showToast(fragment3.getActivity(),(String) response.body().getData());
//                }

                fragment3.setFollowStatus(response.body().getState().equals(APIManager.RESPONSE_OK));
            }

            @Override
            public void onFailure(Call<BaseEntity<String>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
                fragment3.setFollowStatus(false);
            }
        });
    }

    /**
     * 保存图片
     *
     * @param bitmap
     * @param bitName 文件名
     */
    public void saveImageToGallery(Bitmap bitmap, String bitName) {
        String storePath =
                Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath() + "/SGB/";
        File appDir = new File(storePath);
        if (!appDir.exists()) {
            appDir.mkdir();
        }
        File file = new File(storePath, bitName);
        if (file.exists()) {
            file.delete();
        }

        try {
            FileOutputStream out = new FileOutputStream(file);
            if (bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out)) {
                out.flush();
                out.close();
                // 插入图库，不生成缩略图
                ContentValues values = new ContentValues();
                values.put(MediaStore.Images.Media.DATA, file.getAbsolutePath());
                values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
                fragment3.getActivity().getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
                //通知相册有新图片，提醒系统检索导出的图片
                Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                Uri contentUri = Uri.fromFile(file);
                mediaScanIntent.setData(contentUri);
                fragment3.getActivity().sendBroadcast(mediaScanIntent);
                MToast.showToast(fragment3.getActivity(), "保存图片成功！");
            } else {
                MToast.showToast(fragment3.getActivity(), "保存图片失败！");
            }
        } catch (Exception e) {
            MToast.showToast(fragment3.getActivity(), "系统版本过低，保存图片失败！");
            e.printStackTrace();
        }
    }


    public void enquiryImAlternate(String no) {
        DialogHelper.showProgressDialog2(fragment3.getActivity(), null, "取消中...", 0, false, null, false);
        NewAPIManager.getInstance().getCommonAPI().enquiryImAlternate(no).enqueue(new Callback<BaseEntity<EnquiryImAlternateEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<EnquiryImAlternateEntity>> call, Response<BaseEntity<EnquiryImAlternateEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }
                if (response.body().getData() != null && response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    if (response.body().getData().getConfirmType() != null && 2 == response.body().getData().getConfirmType()) {
                        if (!TextUtils.isEmpty(response.body().getData().getConfirmMessage())) {
                            MToast.showToast(fragment3.getActivity(), response.body().getData().getConfirmMessage());
                        }
                    } else {
                        List<EnquiryImAlternateEntity.CompanyCustomersDTO> companyCustomers = response.body().getData().getCompanyCustomers();
                        if (companyCustomers != null) {
                            fragment3.showImWindow(companyCustomers);
                        }
                    }
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<EnquiryImAlternateEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void enquiryOrQuoteImAlternate(String no, String type) {
        DialogHelper.showProgressDialog(fragment3.getActivity(), null, "取消中...", 0, false, null).setCanceledOnTouchOutside(false);
        NewAPIManager.getInstance().getCommonAPI().enquiryOrQuoteImAlternate(no, type).enqueue(new Callback<BaseEntity<EnquiryImAlternateEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<EnquiryImAlternateEntity>> call, Response<BaseEntity<EnquiryImAlternateEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }
                if (response.body().getData() != null && response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    if ("2".equals(response.body().getData().getConfirmType())) {
                        if (!TextUtils.isEmpty(response.body().getData().getConfirmMessage())) {
                            MToast.showToast(fragment3.getActivity(), response.body().getData().getConfirmMessage());
                        }
                    } else {
                        List<EnquiryImAlternateEntity.CompanyCustomersDTO> companyCustomers = response.body().getData().getCompanyCustomers();
                        if (companyCustomers != null) {
                            fragment3.showImWindow(companyCustomers);
                        }
                    }
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<EnquiryImAlternateEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    /**
     * 显示关闭弹窗并实现关闭时的点击事件
     */
    private void showCancelPop(String content, int type) {
        new TipPop(fragment3.getContext(), "温馨提示", content, null, "知道了", new AbstractOnClickPopListener() {
            @Override
            public void onClickCancel() {
                if (type == 1) {
                    fragment3.setType("1");
                    fragment3.setStatus("4");
                    EventBus.getDefault().postSticky(WebEvent.make().setMessageTag(EventConstant.EVENT_WEBVIEW_RELOAD));
                    EventBus.getDefault().post(LeaseEvent.make().setMessageTag(EventConstant.EVENT_BAOJIA_REFRESH));
                } else if (type == 2) {
                    EventBus.getDefault().post(LeaseEvent.make().setMessageTag(EventConstant.EVENT_BAOJIA_REFRESH));
                    fragment3.getActivity().finish();
                }
            }
        }).show();
    }

    /**
     * 文件上传
     */
    public MutableLiveData<UploadFileBean> mFileData = new MutableLiveData<>();

    public void uploadSingleFile(UploadFileBean item) {
        DialogHelper.showProgressDialog(fragment3.getActivity(), null, "取消中...", 0, false, null).setCanceledOnTouchOutside(false);
        File file = new File(item.getFilePath());
        Map<String, RequestBody> photos = new HashMap<>();
        RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);
        photos.put("file" + "\"; filename=\"file." + item.getExtension(), requestBody);
        com.swgk.core.base.api.APIManager.getInstance().create(UploadAPI.class).uploadFile(photos).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {
                DialogHelper.dismissProgressDialog();
                item.setUrlPath(data.getData().toString());
                mFileData.setValue(item);
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                super.onFailure(call, t);
                DialogHelper.dismissProgressDialog();
                mFileData.setValue(item);
            }
        });
    }

    public void getProcessStatus(String companyNo, String approveType, QualityMemberBean memberBean) {
        NewAPIManager.getInstance().getCommonAPI().getProcessStatus(companyNo, approveType).enqueue(new ICallBack<BaseEntity<Object>>() {
            @Override
            public void onSuccess(BaseEntity<Object> data) {
                // "status": "1" //1 表示有审批 0 代表无审批
                String status = ((Map<String, String>) data.getData()).get("status");
                if (!TextUtils.isEmpty(status)) {
                    fragment3.updateProcessStatus(status, memberBean);
                } else {
                    MToast.showToast(fragment3.getActivity(), "网络异常，请稍后重试");
                }
            }
        });
    }
}
